<template>
  <div>
    <el-header>
      <div class="left">学生学业分析系统</div>
      <div class="right">
        <span>欢迎 <i><b>{{ store.user.username }}</b></i> 回来</span>
        <el-dropdown>
          <!-- 远程地址渲染 -->
          <!-- <el-avatar :size="40" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" /> -->
          <!-- 本地地址渲染 -->
          <el-avatar :size="40" :src="circleUrl" />
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>{{roleName}}</el-dropdown-item>
              <el-dropdown-item @click="handleExit">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
  </div>
</template>
<script setup>
import { computed } from 'vue';
import {useRouter} from 'vue-router'
import useUserStore from '../../store/useUserStore'
import useRouterStore from '../../store/useRouterStore'
const router = useRouter()
const store = useUserStore()
const {changeUser,user:{role:{roleName},username}} = useUserStore()
const {changeRouter} = useRouterStore()
// vite上传本地文件的方式
//webpack使用require
const circleUrl = computed(()=>
store.user.avatarUrl?'http://localhost:3000'+store.user.avatarUrl:"https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
)
const avatar = new URL('../../assets/avatar.jpg',import.meta.url).href
const handleExit = () => {
  //清空user
  changeUser({})
  //改变isgetterrouter
  changeRouter(false)
  //跳转页面
  router.push("/login")
}
</script>
<style scoped lang='scss'>
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgb(7, 61, 112);
  border-radius: 10px;
  color: wheat;
  .right{
    span{
      margin-right: 20px;
    }
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>